package com.knife.database.common.utils;


import com.knife.database.common.constants.OracleProperties;
import com.knife.database.common.constants.KnifeJdbcEnv;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

/**
 * Created with IntelliJ IDEA.
 *
 * @author： 76875
 * @date： 2022/7/21 星期四 9:17
 * @description：
 * @modifiedBy：
 * @version: 1.0
 */
public class OracleJdbcUtil {

    public static final Integer defaultIntId = -99;


    public static Connection getConnection(KnifeJdbcEnv knifeJdbcEnv) {
        try {
            OracleProperties properties = knifeJdbcEnv.getProperties();
            Class.forName(properties.getORACLE_DRIVER());
            // 数据库连接对象
            Connection conn = DriverManager.getConnection(properties.getORACLE_URL(), properties.getORACLE_USER(), properties.getORA_PASS_WORD());
            return conn;
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException("获取数据库连接异常");
        }
    }

    public static Statement getStatement(Connection conn) {
        try {
            // 连接的声明
            Statement stmt = conn.createStatement();
            return stmt;
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException("获取数据库连接异常");
        }
    }

    public static void closeConnection(Connection conn) throws Exception {
        conn.close();
    }

    public static void closeStatement(Statement stmt) throws Exception {
        stmt.close();
    }
}
